package com.selune.online.ordering.system.project.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.selune.online.ordering.system.project.api.base.response.Response;
import com.selune.online.ordering.system.project.demo.entity.Demo;
import com.selune.online.ordering.system.project.demo.entity.DemoSearch;
import com.selune.online.ordering.system.project.demo.service.DemoService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiaoyp
 * @date 2020/2/27
 */

@RestController
@RequestMapping("/test")
public class DemoController {
	
	@Autowired
	private DemoService demoService;
	
	@PostMapping("/save")
	@ResponseBody
	public Response<Boolean> save(@RequestBody Demo demo) {
		return demoService.save(demo);
	}
	
	@GetMapping("/list")
	@ResponseBody
	public Response<List<Demo>> list() {
		return demoService.list();
	}
	
	@PutMapping("/update/{id}")
	@ResponseBody
	public Response<Boolean> update(@PathVariable(value = "id") Long id, @RequestBody Demo demo) {
		return demoService.update(id, demo);
	}
	
	@GetMapping("/select/{id}")
	@ResponseBody
	public Response<Demo> select(@PathVariable(value = "id") Long id) {
		return demoService.select(id);
	}
	
	@GetMapping("/page")
	@ResponseBody
	public Response<Page<Demo>> page(Integer current, Integer size) {
		return demoService.page(current, size);
	}
	
	@GetMapping("/page/condition")
	@ResponseBody
	public Response<Page<Demo>> pageByCondition(Integer current, Integer size, DemoSearch demoSearch) {
		return demoService.pageByCondition(current, size, demoSearch);
	}
}
